﻿#region imports

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using CondeNet.AssetManager.Data;
using CondeNet.AssetManager.Business;
using CondeNet.AssetManager.Business.Interface;

#endregion

namespace CondeNet.AssetManager.DataProvider.Sql.Mappers
{
    public static class MetaDataMapper
    {
        internal static IMetaData ToBusinessObject ( T_MetaKey key, T_MetaValue value )
        {
            IMetaData obj = new MetaData (0,
               // entity.MetaData_IDPK ,
                key.MetaKey_IDPK ,
                value.MetaValue_IDPK ,
                String.Empty ,
                String.Empty ,
                DateTime.Now ,
                DateTime.Now );

            if (key != null ) obj.MetaKey = MetaKeyMapper.ToBusinessObject ( key );
            if ( value != null ) obj.MetaValue = MetaValueMapper.ToBusinessObject ( value );

            return obj;
        }

        internal static MetadataPairing ToEntity ( IMetaData v )
        {
            //T_MetaData entity = new T_MetaData ( );
            T_MetaKey keyEntity = new T_MetaKey();
            T_MetaValue valueEntity = new T_MetaValue();

            //keyEntity.MetaKey_IDPK = v.MetaKeyID;

            //entity.MetaData_IDPK = v.ID;
            //entity.MetaKeyID_FK = v.MetaKeyID;
            //valueEntity.MetaValue_IDPK = v.MetaValueID;
//            entity.CreatorID_NVC = v.CreatorID;
  //          entity.LatestEditorID_NVC = v.LatestEditorID;
    //        entity.CreatedDate_DT = v.CreatedDate;
      //      entity.UpdatedDate_DT = v.UpdatedDate;

            if ( v.MetaKey != null ) keyEntity = MetaKeyMapper.ToEntity ( v.MetaKey );
            if ( v.MetaValue != null ) valueEntity = MetaValueMapper.ToEntity ( v.MetaValue );

            return new MetadataPairing{MetaKey=keyEntity,MetaValue = valueEntity};
        }

        internal static IList<IMetaData> ToBusinessObjects ( IList<MetadataPairing> dalList )
        {
            return dalList.Select ( tmp => ToBusinessObject ( tmp.MetaKey,tmp.MetaValue ) ).ToList ( );
        }

        internal static IList<MetadataPairing> ToEntities ( IList<IMetaData> entityList )
        {
            return entityList.Select ( tmp => ToEntity ( tmp ) ).ToList ( );
        }

        public class MetadataPairing
        {
            public T_MetaKey MetaKey { get; set; }
            public T_MetaValue MetaValue { get; set; }
        }
    }
}
